<template>
  <div>
    <div class="header">
      <div class="notLogin" v-if="!this.$store.state.user">
        <img src="@/assets/mobile.png" alt="" @click="$router.push('/')" />
        <span>登录 / 注册</span>
      </div>

      <div class="content">
        <div class="left">
          <van-image fit="cover" :src="user.photo" class="avatar" round />
          <span class="name">{{ user.name }}</span>
        </div>
        <div class="right">
          <van-button
            style="font-size: 14px"
            type="default"
            size="mini"
            round
            @click="$router.push('/details')"
            >编辑资料</van-button
          >
        </div>
      </div>
      <!-- 粉丝、关注 -->
      <div class="data">
        <div class="data-item">
          <span>{{ user.art_count }}</span>
          <span>头条</span>
        </div>
        <div class="data-item">
          <span>{{ user.follow_count }}</span>
          <span>关注</span>
        </div>
        <div class="data-item">
          <span>{{ user.fans_count }}</span>
          <span>粉丝</span>
        </div>
        <div class="data-item">
          <span>{{ user.like_count }}</span>
          <span>获赞</span>
        </div>
      </div>
    </div>

    <van-grid :column-num="2" :border="false">
      <van-grid-item text="收藏">
        <i slot="icon" class="iconfont icon-shoucang"></i>
      </van-grid-item>
      <van-grid-item text="历史">
        <i slot="icon" class="iconfont icon-lishi"></i>
      </van-grid-item>
    </van-grid>
    <van-cell-group style="margin-top: 5px">
      <van-cell title="消息通知" is-link />
      <van-cell title="小智同学" is-link />
    </van-cell-group>

    <van-grid>
      <van-cell
        v-if="this.$store.state.user"
        @click="goOut"
        class="logout-cell"
        title="退出"
      />
    </van-grid>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/user'
export default {
  name: 'userPage',
  components: {},
  props: {},
  data() {
    return {
      user: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getUserInfo()
  },
  methods: {
    goOut() {
      this.$dialog
        .confirm({
          title: '黑马头条',
          message: '是否确认退出该账号？'
        })
        .then(() => {
          // on confirm
          this.isShow = true
          this.$store.commit('setToken', null)
        })
        .catch(() => {
          // on cancel
        })
    },
    async getUserInfo() {
      if (this.$store.state.user) {
        const res = await getUserInfo()
        this.user = res.data.data
      }
    }
  }
}
</script>

<style scoped lang="less">
.header {
  background: url('@/assets/banner.png');
  background-size: 100% 100%;
  width: 100%;
  height: 200px;
  overflow: hidden;
}
.content {
  // 登录成功样式
  display: flex;
  margin-top: 60px;
  width: 100%;
  height: 66px;
  padding: 0px 16px;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  .left {
    display: flex;
    align-items: center;
    .avatar {
      width: 68px;
      height: 68px;
      border: 2px solid #fff;
    }
    .name {
      font-size: 15px;
      margin-left: 17px;
      color: #fff;
    }
  }
}
.notLogin {
  width: 100%;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: #fff;
  font-size: 14px;
  span {
    margin-top: 5px;
  }
  img {
    width: 66px;
  }
}
.icon-shoucang {
  font-size: 23px;
  color: #eb5253;
}
.icon-lishi {
  font-size: 23px;
  color: #ff9d1d;
}
.logout-cell {
  text-align: center;
  color: #eb5253;
  margin: 5px 0;
  font-size: 14px;
}
.data {
  display: flex;
  justify-content: space-around;
  .data-item {
    height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
    span:nth-child(1) {
      font-size: 14px;
      margin-bottom: 5px;
    }
    span:nth-child(2) {
      font-size: 14px;
    }
  }
}
</style>
